package 集合学习.jihe_Set.Setjihewanzheng;

import java.util.Objects;

public class Student implements Comparable<Student>{
    private String name;
    private String sex;
    private int age;
    private double score;

    @Override
    public int compareTo(Student other){//TreeSet需要重写此方法
        return this.name.compareTo(other.name);
    }

    public Student(String name, String sex, int age, double score) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return getAge() == student.getAge() && Double.compare(student.getScore(), getScore()) == 0 && Objects.equals(getName(), student.getName()) && Objects.equals(getSex(), student.getSex());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName(), getSex(), getAge(), getScore());
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }


}
